package test.solr;

import java.io.IOException;
import java.util.List;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocumentList;

import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.druid.DruidPlugin;

import test.maven.Job;

public class App {
	
	public static void main(String[] args) throws IOException {
		System.out.println("solr检索耗时："+solrsearch()+"ms");
		System.out.println("mysql检索耗时："+mysqlsearch()+"ms3");
	}
	
	static long solrsearch() throws IOException {
		String url = "http://localhost:8080/solr";
		HttpSolrClient client = new HttpSolrClient(url);
		SolrQuery query = new SolrQuery("description:互联网");
		try {
			long l1 = System.currentTimeMillis();
			QueryResponse response = client.query("core1", query);
			long l2 = System.currentTimeMillis();
			System.out.println(response.getElapsedTime());
			SolrDocumentList list = response.getResults();
			System.out.println(list.getNumFound());
			return l2-l1;
		} catch (SolrServerException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			client.close();
		}
		return 0;
	}
	
	static long mysqlsearch() {
		DruidPlugin dp = new DruidPlugin("jdbc:mysql://192.168.2.10/licai?characterEncoding=UTF-8", "root", "123456");
		ActiveRecordPlugin arp = new ActiveRecordPlugin(dp);
		arp.setDevMode(true);
		arp.setShowSql(true);
		arp.addMapping("lc_job", Job.class);
		dp.start();
		arp.start();
		long l1 = System.currentTimeMillis();
		List<Record> list = Db.find("select * from lc_job where description like '%互联网%'");
		long l2 = System.currentTimeMillis();
		System.out.println(list.size());
		return l2-l1;
	}

}
